package evo.engine
{
    import flash.display.DisplayObject;
    import flash.display.MovieClip;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.utils.getDefinitionByName;

	public class DefaultPreloader extends MovieClip
	{
    	public static var demo:DefaultPreloader;
    	
        public function DefaultPreloader()
        {
            stop();
            stage.scaleMode = StageScaleMode.NO_SCALE;
            addEventListener(Event.ENTER_FRAME, onEnterFrame);

			//stage.align = StageAlign.TOP_LEFT;
			stage.quality = "medium";
			stage.frameRate=31;
			
			demo=this;
        }
       
        public function onEnterFrame(event:Event):void
        {
            graphics.clear();
            if(framesLoaded == totalFrames)
            {
                removeEventListener(Event.ENTER_FRAME, onEnterFrame);
                nextFrame();
                init();
            }
            else
            {
                var percent:Number = root.loaderInfo.bytesLoaded / root.loaderInfo.bytesTotal;
                graphics.beginFill(0xFFFFFF);
                graphics.drawRect(0, 400 / 2 - 10,
                                  800 * percent, 20);
                graphics.endFill();
            }
        }
       
        private function init():void
        {
            var mainClass:Class = Class(getDefinitionByName("DemoMain"));
            if(mainClass)
            {
                var app:Object = new mainClass();
                addChild(app as DisplayObject);
            }
        }
	}
}